//
//  NSMutableDictionary+Extension.m
//  JKRuntimeMethod_exchange
//
//  Created by 王冲 on 2018/10/10.
//  Copyright © 2018年 JK科技有限公司. All rights reserved.
//

#import "NSMutableDictionary+Extension.h"
#import <objc/runtime.h>
@implementation NSMutableDictionary (Extension)

+(void)load{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        Class cls = NSClassFromString(@"__NSDictionaryM");
        
        // 类簇：NSString、NSArray、NSDictionary，真实类型是其他类型
        Method method1 = class_getInstanceMethod(cls, @selector(setObject:forKeyedSubscript:));
        Method method2 = class_getInstanceMethod(cls,@selector(jk_setObject:forKeyedSubscript:));
        method_exchangeImplementations(method1, method2);
        
        Class cls2 = NSClassFromString(@"__NSDictionaryI");
        
        // 类簇：NSString、NSArray、NSDictionary，真实类型是其他类型
        Method method3 = class_getInstanceMethod(cls2, @selector(objectForKeyedSubscript:));
        Method method4 = class_getInstanceMethod(cls2,@selector(jk_objectForKeyedSubscript:));
        method_exchangeImplementations(method3, method4);

    });
    
    
}

-(void)jk_setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key{
    
    if (!key) {
        return;
    }
    
    [self jk_setObject:obj forKeyedSubscript:(id<NSCopying>)key];
}

-(id)jk_objectForKeyedSubscript:(id)key{
    
    if (!key) {
        return nil;
    }
    
   return [self jk_objectForKeyedSubscript:(id)key];
    
}

@end
